package main

import (
	"net/http"
	"fmt"
	"log"
	"os"
)
var url = "http://www.baidu.com"

func main(){
	if resp, err := http.Get(url); err == nil{
		if resp.StatusCode == http.StatusOK {
			fmt.Println(resp.StatusCode)
		}
		defer resp.Body.Close()
		
		buf := make([]byte, 1024)
		
		content, err1 := os.OpenFile("baidu.html", os.O_RDWR|os.O_CREATE|os.O_APPEND, os.ModePerm)
		if err1 != nil {
			panic(err1)
			return
		}
		defer content.Close()
		
		for {
			n, _ := resp.Body.Read(buf)
			if(n == 0){
				break
			}
			content.WriteString(string(buf[:n]))
		}
		
		
	}else {
		fmt.Println(err)
		log.Fatal(err)
	}
}


//想法，这个http.Get是否是将内容先获取到内存